package cn.mvc.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yexi
 */
public class CustomInterceptor implements HandlerInterceptor {

    /**
     * 前置拦截。在处理方法之前执行。
     * 返回 false，就被拦截；返回 true 就放行访问控制器的处理方法
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse
            response, Object handler) throws Exception {
        System.out.println("preHandle: 前置拦截");
        return true;
    }

    /**
     * 后置拦截。处理方法之后，渲染视图之前。
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse
            response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle: 后置拦截");
    }

    /**
     * 渲染视图之后
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse
            response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion");
    }
}
